package com.travel.controller;

import com.qianfeng.util.ResultMsg;
import com.travel.service.TrainService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;


@RestController
@RequestMapping("/fonttrain")
@Api(value = "火车票购买",description = "前台火车票")
public class FontTrainController {

    @Autowired
    TrainService trainService;

    @GetMapping("/findall")
    public ResultMsg selectAll(@RequestParam(required = false,defaultValue = "1") int current, @RequestParam(required = false,defaultValue = "5") int size){
        return trainService.selectAll(current,size);
    }

    @GetMapping("/sone")
    public ResultMsg selectSnameByLike(String sname){
        return trainService.selectSnameByLike(sname);
    }
    @GetMapping("/eone")
    public ResultMsg selectEnameByLike(String ename){
        return trainService.selectEnameByLike(ename);
    }

    @GetMapping("/eonesone")
    public ResultMsg selectSnameAndEnameByLike(String sname,String ename){
        if (sname.equals(ename)){
            throw new RuntimeException("暂无此售票信息,请重新查询");
        }
        return trainService.selectSnameAndEnameByLike( sname, ename);
    }

    @GetMapping("/eonesone/+{trainId}")
    public ResultMsg selectOneByTid(@RequestParam("trainId") String trainId){
        return trainService.selectOneByTid( trainId);
    }
}
